package com.axjy.controller;

import com.axjy.service.UserService;
import com.axjy.util.Log;
import com.axjy.vo.PageVo;
import com.axjy.vo.UserDto;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/sys/user")
public class UserController {

    @Resource
    private UserService userService;

    private String msg;


    @GetMapping("/search")
    public PageVo search(Integer offset,Integer limit,UserDto dto){
        return userService.search(offset,limit,dto);
    }

    @PostMapping("/grant")
    public String grant(Integer userId,Integer roleId){
        try{
            userService.grant(userId,roleId);
            msg="用户授权成功！";
        }catch (Exception ex){
            msg="用户授权失败！";
            Log.logger.error(msg,ex);
        }
        return msg;
    }
/*
    //rest风格传值
    $.ajax({
        url:"/aaa/bbb/zhangsan/28",
    });

    //序列化字符串传值
    $.ajax({
        url:"/aaa/bbb",
        data:"name=zhangsan&age=28"
    })
    //JSON传值
    $.ajax(
    {
        url:"/url/bbb",

        data:{
        name:"张三那"，
        age:14
    }
       contentType:"application/json"
    }
            )

    @GetMapping("/aaa/bb/{name}/{age}")
    public add(@PathVariable("name") String name, @PathVariable"age" String age){

    }
    @GetMapping("/aaa/bb")
    public add2(@RequestParam("aa") String name,String age){

    }

    [{name:"zhangsan",age:14},{},{}]
   // name=zhangsan&age=18&name=li&age=28
    @GetMapping("/aaa/bb")
    public add2(@RequestBody User[] user){

    }
*/

    @PostMapping("/batchDel")
    public String batchDel(Integer[] ids){
        System.out.println(ids);
        try{
           Integer result= userService.batchDel(ids);
            msg="成功删除"+result+"位员工信息！";
        }catch (Exception ex){
            msg="删除员工失败！";
            Log.logger.error(msg,ex);
        }
        return msg;
    }


}
